﻿var mkUrl = Xwb.util.getBind(Xwb.request, 'mkUrl');
var Util = Xwb.util;
var MsgBox = Xwb.ui.MsgBox;
var Req = Xwb.request;
var getText = Xwb.lang.getText;

function openPop(url, title, act, extcs, form , trigger){
    window.openpop = Xwb.use('MgrDlg', {
        modeUrl: url,
        formMode: true,
        extcs : extcs,
        valcfg: {
            form: form || 'AUTO',
            trigger: '#pop_ok'
        },
        dlgcfg: {
            title: title,
            destroyOnClose: true,
			onclose: function(){
		    	this.auto && this.auto.destroy(1);
				return true;
			},
            onViewReady: function(View){
                var self = this;
                $(View).find('#pop_cancel').click(function(){
                    self.close();
                });
				switch( act ){
				    case 'import':
					    var t = self.auto = Xwb.use("AutoComplate", {  //添加自动搜索控件
							view : "autoComplate",
							appendTo : View,
							resetPos : {left: 130,top: 186},
							relateInp : $(View).find("#spot_name"),
							hdRelateInp : $(View).find("#spot_id"),
							viewWidth : 150,  //$("auto-complate").width()
							reInpWidth : 150,  //$(relateInp).width() + 2 * $(relateInp).css("marginLfet")
							inpHeight : 24    //$(relateInp).height() 
						});
						t.readyToSent(t.relateInp.val());
						
						$(View).find("#btnImport").click(function(){
						    if( !t.hdRelateInp.val() )
							    return Xwb.ui.MsgBox.error('提示',"景点不存在,请重新选择景点"); 
						    var $f = form ? $(View).find(form) : $(View).find("form");
						    Req.postReq($f.attr('action'),$f.serialize(),function(e){
							    if(e.isOk()){
								    location.reload(1);
								}else Xwb.ui.MsgBox.error('提示',e.getError())
								self.close();
							} )
						});
					    break;
				    case 'save':
						$(View).find("#btmSave").click(function(){
						    var $f = form ? $(View).find(form) : $(View).find("form");
						    Req.postReq($f.attr('action'),$f.serialize(),function(e){
							    if(e.isOk()){
								    location.reload(1);
								    self.close();
								}else Xwb.ui.MsgBox.error('提示',e.getError())
							} )
						});
					    break;
					default :
					    return ;
				}
            }
        }
    });
}